function deepClone(value, map = new WeakMap()) {
  if (typeof value !== 'object') return value;
  if (value === null) return null;
  if (value instanceof RegExp) return new RegExp(value);
  if (value instanceof Date) return new Date(value);
  if (map.has(value)) return map.get(value);

  const newObj = value.constructor();
  for (const key in value) {
    if (Object.hasOwn(value, key)) {
      newObj[key] = deepClone(value[key], map);
    }
  }
  return newObj;
}

const a = { age: 3, name: 'yang' };
const b = deepClone(a);
console.log(b);
console.log(a === b);
